Date.prototype.Format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
function formatterDate(date) {
	var y = date.getFullYear();
	var m = date.getMonth() + 1;
	var d = date.getDate();
	return y + '-' + m + '-' + d;
}
$(function(){
	// 添加easyui日期插件
	$('#start').datetimebox({
		formatter : function(date) {
			return date.Format("yyyy-MM-dd hh:mm:ss");
		}
	});
	$('#end').datetimebox({
		formatter : function(date) {
			return date.Format("yyyy-MM-dd hh:mm:ss");
		}
	});
	var d = new Date();
	d.setTime(new Date().getTime() - 30 * 24 * 60 * 60 * 1000);
	$('#start').datetimebox('setValue', d.Format("yyyy-MM-dd hh:mm:ss"));
	$('#end').datetimebox('setValue',new Date().Format("yyyy-MM-dd hh:mm:ss"));
	// 设置日期只读
	$(".datebox :text").attr("readonly", "readonly");
});

$(function(){
	searchSystemFileCount();
});

function searchSystemFileCount() {
	var result = validateDay();
	$.post(ctx + '/monitor/getSystemFileCountCol', 
			{start:result.start,end:result.end} ,
			function(data) {
		buildSystemFileCountCol("systemFileCountMark",data);
	});
}

function strToDate(str) {
	 var tempStrs = str.split(" ");
	 var dateStrs = tempStrs[0].split("-");
	 var year = parseInt(dateStrs[0], 10);
	 var month = parseInt(dateStrs[1], 10) - 1;
	 var day = parseInt(dateStrs[2], 10);
	 var timeStrs = tempStrs[1].split(":");
	 var hour = parseInt(timeStrs [0], 10);
	 var minute = parseInt(timeStrs[1], 10) - 1;
	 var second = parseInt(timeStrs[2], 10);
	 var date = new Date(year, month, day, hour, minute, second);
	 return date;
}
function validateDay() {
	var sd = new Date(strToDate($('#start').datetimebox('getValue')));
	var ed = new Date(strToDate($('#end').datetimebox('getValue')));
	var resultStart = new Date(sd.getTime()).Format("yyyy-MM-dd hh:mm:ss");
	
	if(sd.getTime() > ed.getTime()) {
		$.messager.alert('提示:','起始时间不能大于结束时间！','info');
		return;
	}
	var resultEnd = $('#end').datetimebox('getValue');
	return {start:resultStart, end:resultEnd}
}

function buildSystemFileCountCol(obj, data) {
	new Highcharts.Chart({
        chart: {
        	renderTo: obj,
            type: 'column'
        },
        title: {
            text: "",
            style: {
                fontSize:'13px'
            }
        },
        xAxis: {
        	labels: {  
    	         formatter: function () {  
    	             return this.value;
    	         }  
             }
        },
        xAxis: {
            categories: titles
        },
        yAxis: {
            min: 0,
            title: {
                text: '文件上传数量/文件下载次数 (个/次)'
            }
        },
        tooltip: {  // 表示为 鼠标放在报表图中数据点上显示的数据信息  
        	pointFormatter: function() {
        		 var fix = this.series.name == "文件上传数量" ? " 个" : " 次";
        		 return '<b>'+this.series.name+':</b> ' + this.y + fix;
             }
        },
        plotOptions: {
            column: {
                pointPadding: 0.2,
                borderWidth: 0
            }
        },
        series: data

    });
}